<template>
  <div :style="{ ...coreStyle.marginSame(8) }">
    <a-card>
      <a-form ref="expressionParamFormQueryRef" :model="expressionParamFormQueryModel" labelAlign="left" layout="vertical" :style="{ ...coreStyle.marginBottom(10) }">
        <a-row :gutter="16" v-show="!expressionParamFormQueryVisible">
          <a-col :span="8">
            <a-form-item :style="{ ...coreStyle.marginBottom(-8) }">
              <a-input-search v-model:value="expressionParamFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="expressionParamFormQuerySubmitting" @search="expressionParamFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
            <a-button type="link" :style="{ ...coreStyle.floatRight }" @click="expressionParamFormQueryUpDown">
              展开
              <CoreIcon :icon="coreStyle.antBtnIconExpand" :size="14" />
            </a-button>
          </a-col>
        </a-row>
        <a-row :gutter="16" v-show="expressionParamFormQueryVisible">
          <a-col :span="8">
            <a-form-item>
              <a-input-search v-model:value="expressionParamFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="expressionParamFormQuerySubmitting" @search="expressionParamFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
          </a-col>
          <a-col :span="8">
            <a-form-item label="参数名">
              <a-input v-model:value="expressionParamFormQueryModel.paramNameAndLike" placeholder="输入参数名" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="参数类型">
              <a-input v-model:value="expressionParamFormQueryModel.paramTypeAndLike" placeholder="输入参数类型" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="sql语句Id">
              <a-input v-model:value="expressionParamFormQueryModel.sqlStrIdAndLike" placeholder="输入sql语句Id" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="描述">
              <a-input v-model:value="expressionParamFormQueryModel.descriptionAndLike" placeholder="输入描述" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="排序权重">
              <a-input-number v-model:value="expressionParamFormQueryModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="外键Id">
              <a-input v-model:value="expressionParamFormQueryModel.fkidAndLike" placeholder="输入外键Id" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-space :style="{ ...coreStyle.floatRight }">
              <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="expressionParamFormQueryReset">
                <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
                重置
              </a-button>
              <a-button :loading="expressionParamFormQuerySubmitting" type="dashed" :style="{ ...coreStyle.antBtnQuery }" @click="expressionParamFormQuerySearch">
                <CoreIcon :icon="coreStyle.antBtnIconQuery" :size="14" />
                查询
              </a-button>
              <a-button type="dashed" ghost :style="{ ...coreStyle.antBtnRetract }" @click="expressionParamFormQueryUpDown">
                收起
                <CoreIcon :icon="coreStyle.antBtnIconRetract" :size="14" />
              </a-button>
            </a-space>
          </a-col>
        </a-row>
      </a-form>
      <a-space>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnAdd }" @click="expressionParamAdd">
          <CoreIcon :icon="coreStyle.antBtnIconAdd" :size="14" />
          新增
        </a-button>
        <a-button v-if="expressionParamListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="expressionParamUpdate">
          <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
          修改
        </a-button>
        <a-popconfirm v-if="expressionParamListSelectLength > 0" title="确认删除？" okType="dashed" placement="bottom" @confirm="expressionParamDelete">
          <a-button type="dashed" :style="{ ...coreStyle.antBtnDelete }">
            <CoreIcon :icon="coreStyle.antBtnIconDelete" :size="14" />
            删除
          </a-button>
        </a-popconfirm>
        <a-button v-if="expressionParamListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnDetail }" @click="expressionParamDetailInfo">
          <CoreIcon :icon="coreStyle.antBtnIconDetail" :size="14" />
          详情
        </a-button>
      </a-space>
      <a-space :style="{ ...coreStyle.floatRight }">
        <a-button type="dashed" :style="{ ...coreStyle.antBtnTemplateDownload }" @click="expressionParamTemplateDownload">
          <CoreIcon :icon="coreStyle.antBtnIconTemplateDownload" :size="14" />
          模版下载
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnImport }" @click="expressionParamDataImport">
          <CoreIcon :icon="coreStyle.antBtnIconImport" :size="14" />
          导入
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnExport }" @click="expressionParamDataExport">
          <CoreIcon :icon="coreStyle.antBtnIconExport" :size="14" />
          导出
        </a-button>
        <a-button type="dashed" ghost shape="circle" :style="{ ...coreStyle.antBtnRefresh }" @click="expressionParamListGetDataSet">
          <CoreIcon :icon="coreStyle.antBtnIconRefresh" :size="22" />
        </a-button>
      </a-space>
      <a-table
        rowKey="id"
        :columns="expressionParamListColumns"
        :data-source="expressionParamListDataSet"
        :loading="expressionParamListLoading"
        :pagination="false"
        bordered
        :customRow="expressionParamListCustomRow"
        :row-selection="{ fixed: true, selectedRowKeys: expressionParamListSelectedRowKeys, onChange: expressionParamListRowOnChange }"
        :scroll="{ x: '100%', y: 550 }"
        :style="{ ...coreStyle.marginTop(10) }"
      >
      </a-table>
      <a-pagination
        v-model:current="expressionParamListDataPage"
        v-model:pageSize="expressionParamListDataRows"
        :total="expressionParamListDataCount"
        show-size-changer
        show-quick-jumper
        :page-size-options="[ ...coreStyle.antdPaginationPageSizeOptions ]"
        :show-total="(total, range) => coreStyle.antdPaginationShowTotal(total, range)"
        :style="{ ...coreStyle.marginTop(10), ...coreStyle.textAlignCenter }"
        @change="expressionParamListPaginationChange"
        @showSizeChange="expressionParamListPaginationShowSizeChange"
        v-if="expressionParamListPaginationVisible"
      >
      </a-pagination>
      <p :style="{ ...coreStyle.marginTop(14), ...coreStyle.marginBottom(6), ...coreStyle.textAlignCenter }" v-if="!expressionParamListPaginationVisible">
        {{ coreStyle.antdPaginationShowTotal(expressionParamListDataCount) }}
      </p>
    </a-card>
    <a-drawer
      v-model:visible="expressionParamEditDrawerVisible"
      title="编辑公式参数信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
      @close="expressionParamEditDrawerOnClose"
    >
      <a-form ref="expressionParamFormRef" :model="expressionParamFormModel" :rules="expressionParamFormRules" labelAlign="left" layout="vertical">
        <a-row :gutter="16">
          <a-col :span="12">
            <a-form-item label="参数名" name="paramName">
              <a-input v-model:value="expressionParamFormModel.paramName" placeholder="输入参数名" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="参数类型" name="paramType">
              <a-input v-model:value="expressionParamFormModel.paramType" placeholder="输入参数类型" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="sql语句Id" name="sqlStrId">
              <a-input v-model:value="expressionParamFormModel.sqlStrId" placeholder="输入sql语句Id" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="描述" name="description">
              <a-input v-model:value="expressionParamFormModel.description" placeholder="输入描述" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="排序权重" name="weightOrder">
              <a-input-number v-model:value="expressionParamFormModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="外键Id" name="fkid">
              <a-input v-model:value="expressionParamFormModel.fkid" placeholder="输入外键Id" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="expressionParamFormReset">
            <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
            重置
          </a-button>
          <a-button :loading="expressionParamFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnNextAdd }" @click="expressionParamFormNextAdd">
            <CoreIcon :icon="coreStyle.antBtnIconNextAdd" :size="14" />
            继续录入
          </a-button>
          <a-button :loading="expressionParamFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnSave }" @click="expressionParamFormSave">
            <CoreIcon :icon="coreStyle.antBtnIconSave" :size="14" />
            保存
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="expressionParamDetailDrawerVisible"
      title="公式参数详细信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
    >
      <a-space direction="vertical" :size="20" :style="{ ...coreStyle.width('100%') }">
        <a-descriptions title="基础信息" :column="2" bordered>
          <a-descriptions-item label="参数名" :span="1">{{ expressionParamDetailModel.paramName }}</a-descriptions-item>
          <a-descriptions-item label="参数类型" :span="1">{{ expressionParamDetailModel.paramType }}</a-descriptions-item>
          <a-descriptions-item label="sql语句Id" :span="1">{{ expressionParamDetailModel.sqlStrId }}</a-descriptions-item>
          <a-descriptions-item label="描述" :span="1">{{ expressionParamDetailModel.description }}</a-descriptions-item>
          <a-descriptions-item label="排序权重" :span="1">{{ expressionParamDetailModel.weightOrder }}</a-descriptions-item>
          <a-descriptions-item label="外键Id" :span="1">{{ expressionParamDetailModel.fkid }}</a-descriptions-item>
        </a-descriptions>
      </a-space>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="expressionParamDetailUpdate">
            <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
            修改
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="expressionParamDataImportDrawerVisible"
      title="公式参数数据导入"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <a-row :gutter="16">
        <a-col :span="24">
          <FileUpload ref="expressionParamDataImportFileUploadRef" :fileModule="expressionParamDataImportFileModule" @change="expressionParamDataImportFileUploadChange" />
          <a-input v-model:value="expressionParamDataImportFileUrl" disabled addonBefore="导入文件url:" placeholder="输入导入文件url">
            <template #addonAfter>
              <a-button type="link" size="small" @click="expressionParamDataImportFileUrlSelectFileClick">选择文件</a-button>
            </template>
          </a-input>
        </a-col>
      </a-row>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button :loading="expressionParamDataImportSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnImportData }" @click="expressionParamToDataImport">
            <CoreIcon :icon="coreStyle.antBtnIconImportData" :size="14" />
            导入数据
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="expressionParamDataImportFileSelectDrawerVisible"
      title="文件选择"
      placement="right"
      :closable="false"
      destroyOnClose
      :width="'80%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 0, 0) }"
    >
      <FileSelect :fileModule="expressionParamDataImportFileModule" @change="expressionParamDataImportFileSelectChange" />
    </a-drawer>
    <a-drawer
      v-model:visible="expressionParamDataExportDrawerVisible"
      title="公式参数数据导出"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <DataExportColumnSelect :optionalDataExportFieldList="expressionParamOptionalDataExportFieldList" :selectedDataExportFieldList="expressionParamSelectedDataExportFieldList" />
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnQueryDataExport }" @click="expressionParamToDataExport(false)">
            <CoreIcon :icon="coreStyle.antBtnIconQueryDataExport" :size="14" />
            查询数据导出
          </a-button>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnAllDataExport }" @click="expressionParamToDataExport(true)">
            <CoreIcon :icon="coreStyle.antBtnIconAllDataExport" :size="14" />
            全部数据导出
          </a-button>
        </a-space>
      </div>
    </a-drawer>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component'
import { mapStores } from 'pinia'
import { useCoreToolStore } from '/@/store/modules/cn/core/tool/coreToolStore'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import type { DataExportFieldAO } from '/@/model/cn/core/tool/ao/DataExportFieldAO'
import type { DataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'
import { toDataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'

import { useExpressionParamStore } from '/@/store/modules/cn/core/kpis/expressionParamStore'

import type { ExpressionParam } from '/@/model/cn/core/kpis/eo/ExpressionParam'
import { toExpressionParam } from '/@/model/cn/core/kpis/eo/ExpressionParam'

import type { ExpressionParamQO } from '/@/model/cn/core/kpis/qo/ExpressionParamQO'
import { toExpressionParamQO } from '/@/model/cn/core/kpis/qo/ExpressionParamQO'

import type { ExpressionParamVO } from '/@/model/cn/core/kpis/vo/ExpressionParamVO'
import { toExpressionParamVO } from '/@/model/cn/core/kpis/vo/ExpressionParamVO'

@Options({
  name: 'ExpressionParam',
  components: {
  },
  computed: {
    ...mapStores(useCoreToolStore, useExpressionParamStore),
  },
})
export default class ExpressionParam extends Vue {

  expressionParamListDataSet: Array<ExpressionParamVO> = []

  expressionParamListColumns: Array<object> = [
    {
      title: '参数名',
      dataIndex: 'paramName',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '参数类型',
      dataIndex: 'paramType',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: 'sql语句Id',
      dataIndex: 'sqlStrId',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '描述',
      dataIndex: 'description',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '排序权重',
      dataIndex: 'weightOrder',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '外键Id',
      dataIndex: 'fkid',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
  ]

  expressionParamListLoading: boolean = false

  expressionParamListSelectedRowKeys: string[] = []

  expressionParamListSelectData: Array<ExpressionParamVO> = []

  expressionParamListSelectLength: number = 0

  expressionParamListSelectCurrentRowIndex: number = -1

  expressionParamListSelectCurrentRowData: ExpressionParamVO = toExpressionParamVO()

  expressionParamListPaginationVisible: boolean = true

  expressionParamListDataPage: number = 1

  expressionParamListDataRows: number = 10

  expressionParamListDataCount: number = 0

  expressionParamListRowClickTimeout: number | null = null

  expressionParamListRowOnChange(selectedRowKeys, selectedRows) {
    this.expressionParamListSelectedRowKeys = [ ...selectedRowKeys ]
    this.expressionParamListSelectData = [ ...selectedRows ]
    this.expressionParamListSelectLength = selectedRows.length
  }

  expressionParamListCustomRow(record, index) {
    return {
      'class': index === this.expressionParamListSelectCurrentRowIndex ? 'ant-table-row-selected' : '',
      onClick: (event) => {
        if (this.expressionParamListRowClickTimeout) {
          clearTimeout(this.expressionParamListRowClickTimeout)
          this.expressionParamListRowClickTimeout = null
        } else {
          this.expressionParamListRowClickTimeout = setTimeout(() => {
            this.expressionParamListRowClickTimeout = null
            this.expressionParamListSelectCurrentRowIndex = index
            this.expressionParamListSelectCurrentRowData = { ...record }
            let selectedRowKeys = [ ...this.expressionParamListSelectedRowKeys ]
            let selectedRows = [ ...this.expressionParamListSelectData ]
            if (selectedRowKeys.includes(record.id)) {
              this.expressionParamListRowOnChange([ ...selectedRowKeys.filter(eo => { return eo !== record.id }) ], [ ...selectedRows.filter(eo => { return eo.id !== record.id }) ])
            } else {
              selectedRowKeys.push(record.id)
              selectedRows.push(record)
              this.expressionParamListRowOnChange([ ...new Set(selectedRowKeys) ], [ ...new Set(selectedRows) ])
            }
          }, 200)
        }
      },
      onDblclick: (event) => {
        this.expressionParamStore.pkVo(this.$toParam<ExpressionParamQO>({ id: record.id } as ExpressionParamQO)).then((res: Res<ExpressionParamVO>) => {
          if (res.succ) {
            this.expressionParamDetailModel = { ...res.data[0] }
            this.expressionParamDetailDrawerVisible = true
          } else {
            this.$message.error(res.msg, 6)
          }
        })
      },
    }
  }

  expressionParamListGetDataSet() {
    this.expressionParamListLoading = true
    this.expressionParamListRowOnChange([], [])
    this.expressionParamListSelectCurrentRowIndex = -1
    this.expressionParamListSelectCurrentRowData = toExpressionParamVO()
    this.expressionParamStore.pagingVo(this.$toParam<ExpressionParamQO>({ weightOrderAsc: 'y' } as ExpressionParamQO, this.expressionParamListDataPage, this.expressionParamListDataRows)).then((res: Res<ExpressionParamVO>) => {
      if (res.succ) {
        this.expressionParamListPaginationVisible = true
        this.expressionParamListDataSet = [ ...res.data ]
        this.expressionParamListDataCount = res.count
        setTimeout(() => { this.expressionParamListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.expressionParamListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.expressionParamListLoading = false }, 500)
    })
  }

  expressionParamListPaginationChange() {
    this.expressionParamListGetDataSet()
  }

  expressionParamListPaginationShowSizeChange() {
    this.expressionParamListGetDataSet()
  }

  expressionParamFormQueryVisible: boolean = false

  expressionParamFormQuerySubmitting: boolean = false

  expressionParamFormQueryModel: ExpressionParamQO = toExpressionParamQO()

  expressionParamFormQueryUpDown() {
    this.expressionParamFormQueryVisible = !this.expressionParamFormQueryVisible
  }

  expressionParamFormQueryReset() {
    if (this.$refs.expressionParamFormQueryRef) {
      this.$refs.expressionParamFormQueryRef.resetFields()
      this.expressionParamFormQueryModel = toExpressionParamQO()
    }
  }

  expressionParamFormQuerySearch() {
    this.expressionParamFormQuerySubmitting = true
    this.expressionParamListLoading = true
    this.expressionParamListRowOnChange([], [])
    this.expressionParamListSelectCurrentRowIndex = -1
    this.expressionParamListSelectCurrentRowData = toExpressionParamVO()
    this.expressionParamStore.queryVo(this.$toParam<ExpressionParamQO>(this.$toSearch({ ...this.expressionParamFormQueryModel }))).then((res: Res<ExpressionParamVO>) => {
      if (res.succ) {
        this.expressionParamListPaginationVisible = false
        this.expressionParamListDataSet = [ ...res.data ]
        this.expressionParamListDataCount = res.count
        setTimeout(() => { this.expressionParamFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.expressionParamListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.expressionParamFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.expressionParamListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.expressionParamFormQuerySubmitting = false }, 5000)
      setTimeout(() => { this.expressionParamListLoading = false }, 500)
    })
  }

  expressionParamEditDrawerVisible: boolean = false

  expressionParamFormSaveSubmitting: boolean = false

  expressionParamFormSaveContinue: boolean = false

  expressionParamFormModel: ExpressionParam = toExpressionParam()

  expressionParamFormRules: object = {
    // paramName: [
    //   { type: 'string', required: true, message: '参数名不能为空！', trigger: ['change', 'blur'] },
    // ],
    // paramType: [
    //   { type: 'string', required: true, message: '参数类型不能为空！', trigger: ['change', 'blur'] },
    // ],
    // sqlStrId: [
    //   { type: 'string', required: true, message: 'sql语句Id不能为空！', trigger: ['change', 'blur'] },
    // ],
    // description: [
    //   { type: 'string', required: true, message: '描述不能为空！', trigger: ['change', 'blur'] },
    // ],
    // weightOrder: [
    //   { type: 'number', required: true, message: '排序权重不能为空！', trigger: ['change', 'blur'] },
    // ],
    // fkid: [
    //   { type: 'string', required: true, message: '外键Id不能为空！', trigger: ['change', 'blur'] },
    // ],
  }

  expressionParamFormReset() {
    if (this.$refs.expressionParamFormRef) {
      this.$refs.expressionParamFormRef.resetFields()
      this.expressionParamFormModel = toExpressionParam()
    }
  }

  expressionParamFormSubmit() {
    this.expressionParamFormSaveSubmitting = true
    this.$refs.expressionParamFormRef.validate().then(() => {
      if (this.expressionParamFormModel.id) {
        this.expressionParamStore.update(this.$toParam<ExpressionParam>(this.expressionParamFormModel)).then((res: Res<ExpressionParam>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.expressionParamFormReset()
            this.expressionParamFormSaveSubmitting = false
            if (!this.expressionParamFormSaveContinue) {
              this.expressionParamEditDrawerVisible = false
              this.expressionParamListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.expressionParamFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.expressionParamFormSaveSubmitting = false }, 3000)
        })
      } else {
        this.expressionParamStore.save(this.$toParam<ExpressionParam>(this.expressionParamFormModel)).then((res: Res<ExpressionParam>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.expressionParamFormReset()
            this.expressionParamFormSaveSubmitting = false
            if (!this.expressionParamFormSaveContinue) {
              this.expressionParamEditDrawerVisible = false
              this.expressionParamListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.expressionParamFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.expressionParamFormSaveSubmitting = false }, 3000)
        })
      }
    }).catch(() => {
      setTimeout(() => { this.expressionParamFormSaveSubmitting = false }, 3000)
    })
  }

  expressionParamFormSave() {
    this.expressionParamFormSaveContinue = false
    this.expressionParamFormSubmit()
  }

  expressionParamFormNextAdd() {
    this.expressionParamFormSaveContinue = true
    this.expressionParamFormSubmit()
  }

  expressionParamAdd() {
    if (this.expressionParamFormModel.id) {
      this.expressionParamFormReset()
    }
    this.expressionParamEditDrawerVisible = true
  }

  expressionParamUpdate() {
    this.expressionParamStore.pk(this.$toParam<ExpressionParamQO>({ id: this.expressionParamListSelectData[0].id } as ExpressionParamQO)).then((res: Res<ExpressionParam>) => {
      if (res.succ) {
        this.expressionParamFormReset()
        this.expressionParamFormModel = { ...res.data[0] }
        this.expressionParamEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  expressionParamEditDrawerOnClose() {
    if (this.expressionParamFormSaveContinue) {
      this.expressionParamFormSaveContinue = false
      this.expressionParamListGetDataSet()
    }
  }

  expressionParamDelete() {
    let param: Array<ExpressionParam> = []
    this.expressionParamListSelectData.forEach((eo: ExpressionParamVO) => {
      param.push({ id: eo.id } as ExpressionParam)
    })
    this.expressionParamStore.removeBatch(this.$toParam<ExpressionParam>(param)).then((res: Res<ExpressionParam>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.expressionParamListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  expressionParamDetailDrawerVisible: boolean = false

  expressionParamDetailModel: ExpressionParamVO = toExpressionParamVO()

  expressionParamDetailInfo() {
    this.expressionParamStore.pkVo(this.$toParam<ExpressionParamQO>({ id: this.expressionParamListSelectData[0].id } as ExpressionParamQO)).then((res: Res<ExpressionParamVO>) => {
      if (res.succ) {
        this.expressionParamDetailModel = { ...res.data[0] }
        this.expressionParamDetailDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  expressionParamDetailUpdate() {
    this.expressionParamStore.pk(this.$toParam<ExpressionParamQO>({ id: this.expressionParamDetailModel.id } as ExpressionParamQO)).then((res: Res<ExpressionParam>) => {
      if (res.succ) {
        this.expressionParamFormReset()
        this.expressionParamFormModel = { ...res.data[0] }
        this.expressionParamDetailDrawerVisible = false
        this.expressionParamEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  expressionParamTemplateDownload() {
    this.coreToolStore.getValueByConfKey('defaultDataImportTemplate').then((res: string) => {
      window.open(this.coreToolStore.getFileFullUrl(res), '_blank')
    })
  }

  expressionParamDataImportDrawerVisible: boolean = false

  expressionParamDataImportFileSelectDrawerVisible: boolean = false

  expressionParamDataImportFileModule: string = 'dataImport'

  expressionParamDataImportFileUrl: string = ''

  expressionParamDataImportSaveSubmitting: boolean = false

  expressionParamDataImport() {
    this.expressionParamDataImportDrawerVisible = true
  }

  expressionParamDataImportFileUploadChange(value) {
    this.expressionParamDataImportFileUrl = value
  }

  expressionParamDataImportFileUrlSelectFileClick() {
    this.expressionParamDataImportFileSelectDrawerVisible = true
  }

  expressionParamDataImportFileSelectChange(fileUrl) {
    this.expressionParamDataImportFileUrl = fileUrl
    this.expressionParamDataImportFileSelectDrawerVisible = false
  }

  expressionParamToDataImport() {
    this.expressionParamDataImportSaveSubmitting = true
    this.expressionParamStore.dataImport(this.$toParam<string>(this.expressionParamDataImportFileUrl)).then((res: Res<ExpressionParam>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.$refs.expressionParamDataImportFileUploadRef.resetFiles()
        this.expressionParamDataImportFileUrl = ''
        this.expressionParamDataImportSaveSubmitting = false
        this.expressionParamDataImportDrawerVisible = false
        this.expressionParamListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.expressionParamDataImportSaveSubmitting = false }, 3000)
      }
    }).catch(err => {
      setTimeout(() => { this.expressionParamDataImportSaveSubmitting = false }, 3000)
    })
  }

  expressionParamDataExportDrawerVisible: boolean = false

  expressionParamOptionalDataExportFieldList: Array<DataExportFieldAO> = [
    {
      fieldName: 'paramName',
      fieldComment: '参数名',
    },
    {
      fieldName: 'paramType',
      fieldComment: '参数类型',
    },
    {
      fieldName: 'sqlStrId',
      fieldComment: 'sql语句Id',
    },
    {
      fieldName: 'description',
      fieldComment: '描述',
    },
    {
      fieldName: 'weightOrder',
      fieldComment: '排序权重',
    },
    {
      fieldName: 'fkid',
      fieldComment: '外键Id',
    },
  ]

  expressionParamSelectedDataExportFieldList: Array<DataExportFieldAO> = []

  expressionParamDataExport() {
    this.expressionParamDataExportDrawerVisible = true
  }

  expressionParamToDataExport(allData: boolean) {
    this.expressionParamStore.dataExport(this.$toParam<DataExportAO<ExpressionParamQO>>(toDataExportAO(this.expressionParamSelectedDataExportFieldList, allData ? { weightOrderAsc: 'y' } as ExpressionParamQO : this.$toSearch({ ...this.expressionParamFormQueryModel }), '公式参数信息数据导出.xlsx'))).then((res: Res<string>) => {
      if (res.succ) {
        window.open(this.coreToolStore.getFileFullUrl(res.data[0]), '_blank')
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  mounted() {
    this.expressionParamListGetDataSet()
  }

}
</script>

<style scoped lang="less">

</style>
